<?php

/**
 * pointsCalculation actions.
 *
 * @package    cpfaizenay
 * @subpackage partner
 * @author     Manu
 * @version    1.0
 */
class pointsCalculationActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request) {
      $this->licensee_point_list = null;
      if($this->getUser()->isAuthenticated()){
          $id_user = $this->getUser()->getGuardUser()->getId();
          $this->licensee_point_list = Doctrine::getTable('LicenseePoint')->getLicenseeUserPoint($id_user)->fetchArray();
      }

      $this->form = new PointsCalculationForm();
      unset($this->form['datetime_match']);
      
      isicsBreadcrumbs::getInstance()->addItem('Calcul de points', '#');

      $response = $this->getResponse();
      Utils::setSlogTitle('Calcul de points', $response);
  }

  public function executeDoCalculate(sfWebRequest $request) {
      $this->forward404Unless($request->isMethod('post'));
      $this->scoring_table = Doctrine::getTable('ScoringTable')->getScoringTable()->fetchArray();
      $this->forward404Unless($this->scoring_table);

      $results = $request->getParameter('points_calculation');
      $this->forward404Unless($results);

      $this->results = $results['licensee_match'];
      $this->mensual_points = $results['mensual_points'];
      $this->mensual_points = $this->mensual_points > 0 ? $this->mensual_points : 0;

      $id_matchType = $results['match_type'];
      $this->matchType = null;
      if(!empty($id_matchType)){
        $this->matchType = Doctrine::getTable('MatchType')->getCurrentMatchType($id_matchType)->fetchOne();
      }

      isicsBreadcrumbs::getInstance()->addItem('Calcul de points', '#');

      $response = $this->getResponse();
      Utils::setSlogTitle('Calcul de points', $response);
  }
}